home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / libraries / supralib.lha / SupraLib / doc / supra.doc < prev    next >
Encoding:
Text File  |  1995-03-08  |  21.3 KB  |  640 lines

  1. TABLE OF CONTENTS
  2.  
  3. FCopy
  4. FileType
  5. FreeNewImg
  6. MakeNewImg
  7. MakePath
  8. ObtPens
  9. RecDirFree
  10. RecDirInit
  11. RecDirNext
  12. RecDirTags
  13. RelPens
  14. FCopy                                                                   FCopy
  15.  
  16.    NAME
  17.        FCopy -- copies source file to destination file (V10)
  18.        (dos V36)
  19.  
  20.    SYNOPSIS
  21.        error = FCopy(source, dest, buffer)
  22.  
  23.        UBYTE = FCopy(char *, char *, LONG);
  24.  
  25.    FUNCTION
  26.        This function works very similar to C:Copy program. It copies
  27.        a source file to a destination file.
  28.  
  29.    INPUTS
  30.        source - pointer to a source file name (with a relative or
  31.                 absolute path)
  32.        dest - pointer to a destination file name
  33.        buffer - maximum size of a buffer (in bytes) to be
  34.                 allocated for copying. If this buffer is 0, FCopy()
  35.                 will try to allocate buffer a size of a source file,
  36.                 or the largest memory block available. (this is the
  37.                 fastest way).
  38.  
  39.    RESULT
  40.        error - zero if no error. Function may return one of the
  41.        following error definitions:
  42.  
  43.            FC_ERR_EXIST - Source file does not exist
  44.            FC_ERR_EXAM  - Error during examination of a source file
  45.            FC_ERR_MEM   - Not enough memory availabe
  46.            FC_ERR_OPEN  - Source file could not be oppened
  47.            FC_ERR_READ  - Error while reading a source file
  48.            FC_ERR_DIR   - Source file path is a directory
  49.            FC_ERR_DEST  - Destination file could not be created
  50.            FC_ERR_WRITE - Error while writing to a destination file
  51.  
  52.    EXAMPLE
  53.  
  54.        /* This example will copy a file c:dir to ram: with a new name
  55.         * list.
  56.         */
  57.  
  58.        UBYTE err;
  59.  
  60.        if ((err = FCopy("C:Dir", "ram:list", 0)) == 0) {
  61.  
  62.            no errors...
  63.  
  64.        } else {
  65.            printf("Error: %d\n", err); /* Error occured during FCopy() */
  66.  
  67.        }
  68.  
  69.    NOTES
  70.        If an error occurs then a destination file will not be deleted
  71.        if it has already been partly copied.
  72.  
  73. FileType                                                             FileType
  74.  
  75.    NAME
  76.        FileType -- Examines if a file is a directory or a file (V10)
  77.  
  78.    SYNOPSIS
  79.        type = FileType(filename)
  80.  
  81.        LONG = FileType(char *);
  82.  
  83.    FUNCTION
  84.        Will use dos.library's Examine() function to determine
  85.        whether a specified file(path) exists, and if it is a file
  86.        or a directory.
  87.  
  88.    INPUTS
  89.        filename - pointer to a filename string
  90.  
  91.    RESULT
  92.        returns 0 if specified file/path does not exist. If < 0, then
  93.        it is a plain file. If > 0 a directory.
  94.        This function actually returns fib_DirEntryType (from
  95.        struct FileInfoBlock).
  96.  
  97.    EXAMPLE
  98.  
  99.        type = FileType("SYS:System");
  100.  
  101.        type will be > 0, which means that "SYS:System" is a dir.
  102.  
  103. FreeNewImg                                                         FreeNewImg
  104.  
  105.    NAME
  106.        FreeNewImg -- frees memory allocated by MakeNewImg() (V10)
  107.  
  108.    SYNOPSIS
  109.        FreeNewImg(newImage)
  110.  
  111.        void FreeNewImg(struct Image *);
  112.  
  113.    FUNCTION
  114.        You must free a new created image with this function, when
  115.        it is no longer needed.
  116.  
  117.    SEE ALSO
  118.        MakeNewImg()
  119.  
  120. MakeNewImg                                                         MakeNewImg
  121.  
  122.    NAME
  123.        MakeNewImg -- Remap an image to any new colours (V10)
  124.  
  125.    SYNOPSIS
  126.        newImage = MakeNewImg(oldImage, palette)
  127.  
  128.        struct Image * = MakeNewImg(struct Image *, ULONG *);
  129.  
  130.    FUNCTION
  131.        This function creates a new clone image of a provided
  132.        image, and it remaps the new image according to a provided
  133.        pen colour list.
  134.        This is very useful when you need your image to use
  135.        specific colours anywhere in the available palette.
  136.        (e.g. you obtained some free pens from a palette, and
  137.        you want your image to be shown with those pens).
  138.        It is possible to modify an image's pens with PlanePick and
  139.        PlaneOnOff fields (see Image structure), but this has a major
  140.        limitation: most colour combinations are not possible to get.
  141.  
  142.        If your image has four colours (0,1,2,3), and you want to
  143.        remap these to (0,16,4,7), you simply call this function,
  144.        providing it with the image and a new colour map, and a
  145.        new image will be created for you.
  146.  
  147.    INPUTS
  148.        oldImage - pointer to an Image structure to be remapped
  149.        palette  - pointer to a list of new pens
  150.  
  151.        A pens list should contain the exact number of pens as
  152.        an old image uses. (2 if image's depth is 1, 4 if image's
  153.        depth is 2, etc.). An image's colour 0 will be remapped to the
  154.        first pen on the list, image's colour 1 will be remapped to
  155.        the second pen on the list and so on.
  156.  
  157.    RESULT
  158.        newImage - pointer to a newly initialized remapped old image's
  159.                   clone. If there is not enough memory, newImage will
  160.                   be NULL.
  161.        IMPORTANT: If a new image was created you have to call
  162.        FreeNewImg() to free the allocated memory, when you no longer
  163.        need to use it!
  164.  
  165.    EXAMPLE
  166.  
  167.        We have a depth 2 image (4 colours), and we want to use pens
  168.        0,16,4,7 instead of 0,1,2,3:
  169.  
  170.  
  171.        struct Image OldImage = {
  172.            ....    /* This is a data of our original image */
  173.  
  174.        struct Image *NewImage;
  175.        ULONG pal[] = {0, 16, 4, 7}; /* The new pen list */
  176.  
  177.        if (NewImage = MakeNewImg(&OldImage, &pal[0])) {
  178.           DrawImage(rp, NewImage);
  179.           FreeNewImg(NewImage);    /* We will no longer use it */
  180.        }
  181.  
  182.    NOTE
  183.        A new image's depth will change to a depth that can hold
  184.        the largest pen number from a pens list. It does not have
  185.        any smart routine to check if the depth can be optimized
  186.        down, by altering PlanePick and PlaneOnOff, yet.
  187.        Bear in mind that if you provide a pen 255, then a new image's
  188.        depth will be at least 8.
  189.  
  190.        You MUST free a new image with FreeNewImg() when it's no longer
  191.        needed!
  192.  
  193.        This function can take much time when remapping larger images
  194.        with more depths.
  195.  
  196.    BUGS
  197.        None found.
  198.  
  199.    SEE ALSO
  200.        FreeNewImg()
  201.  
  202. MakePath                                                             MakePath
  203.  
  204.    NAME
  205.        MakePath -- Creates all new directories in a path (V10)
  206.  
  207.    SYNOPSIS
  208.        suc = MakePath(path)
  209.  
  210.        BOOL = MakePath(char *);
  211.  
  212.    FUNCTION
  213.        This function creates a whole specified path of directories.
  214.        It works similar to CreateDir() except that it can create
  215.        more subdirs at once. User does not have to care if all
  216.        sub dirs in a specified path already exist or not.
  217.  
  218.    INPUTS
  219.        path - pointer to a path string to create. A path can be
  220.        relative to a current dir or absolute.
  221.  
  222.    RESULT
  223.        suc - TRUE if succeeds (path was created). FALSE if a path
  224.        could not be created.
  225.  
  226.    EXAMPLE
  227.  
  228.        suc = MakePath("RAM:way/to/many/dirs");
  229.  
  230.        The above function will try to make all non-existing dirs
  231.        in a path RAM:way/to/many/dirs.
  232.  
  233.    SEE ALSO
  234.        CreateDir()
  235.  
  236. ObtPens                                                               ObtPens
  237.  
  238.    NAME
  239.        ObtPens -- Obtain best pens from a list of colors (V10)
  240.        (gfx V39)
  241.  
  242.    SYNOPSIS
  243.        number = ObtPens(cm, PalTable, PensTable, TagItem)
  244.  
  245.        ULONG  = ObtPens(struct ColorMap *, ULONG *, ULONG *,
  246.                  struct TagItem *);
  247.  
  248.    FUNCTION
  249.        This function calls ObtainBestPen() on a list of color
  250.        entries, and puts results into a new pens list.
  251.  
  252.        It will attempt to find colors in your viewport closest to
  253.        the provided colors list (PalTable).
  254.        This is usefull when you want to use an image with more
  255.        specific colors on a public screen with a sharable palette.
  256.  
  257.    INPUTS
  258.        cm = colormap
  259.        PalTable - list of RGB entries for each color you want to use.
  260.                   The format of this table is the same as for LoadRGB32():
  261.  
  262.              1 Word with the number of colors to obtain
  263.              1 Word with the first color to be obtained
  264.              3 longwords representing a left justified 32 bit RGB triplet
  265.              The list is terminated by a count value of 0.
  266.  
  267.              examples:
  268.                ULONG PalTable[]={2l<<16+1,0,0,0, 0xffffffff,0,0, 0};
  269.                    two entries (black, red); obtains only red one
  270.  
  271.        PensTable - list of pen numbers on your viewport, obtained by
  272.                    this function. First entry in PensTable will represent
  273.                    the first color in PalTable, and so on.
  274.                    NOTE that entries in PensTable with count number lower
  275.                    than the first color to be obtained (provided in
  276.                    PalTable) will be unaffected!
  277.  
  278.        TagItem - this tagitem will be passed to ObtainBestPen() function,
  279.                  that is called within ObtPens(). Please see ObtainBestPen()
  280.                  in order to decide what kind of precision for obtaining
  281.                  colors you will need. If this is NULL, PRECISION_IMAGE will
  282.                  be used.
  283.  
  284.    RESULT
  285.        number = number of obtained colours (always the same as the first
  286.        Word in PalTable), or 0 if failed. If it succeeds you must call
  287.        RelPens() to free obtained colors.
  288.  
  289.  
  290.    EXAMPLES
  291.  
  292.        The following example will obtain red, green and blue colours in a
  293.        viewport, and will put obtained pens into pens[] table. pens[0] will
  294.        be untouched (will remain the same colour as viewport's background).
  295.  
  296.        ULONG pal[((4<<16)+1, /* 4 entries, starting with the second one */
  297.                    0, 0, 0,          /* black - will ignore this one */
  298.                    0xffffffff, 0, 0, /* red */
  299.                    0, 0xffffffff, 0, /* green */
  300.                    0, 0, 0xffffffff, /* blue */
  301.                    0};
  302.  
  303.        ULONG pens[4];
  304.  
  305.        ObtPens(cm, pal, pens, NULL);
  306.  
  307.        SetAPen(rp, pens[1]);   /* Set the primary pen to red */
  308.        Text(rp, "I'm red!", 8);
  309.  
  310.  
  311.    NOTES
  312.        You MUST call RelPens() to free all obtained colors if ObtPens()
  313.        have succeeded, but you must not call it if ObtPens() returns 0.
  314.        You MUST open graphics library (V39 or higher) before calling this
  315.        function.
  316.  
  317.    SEE ALSO
  318.        RelPens(), ObtainBestPen(), LoadRGB32()
  319.  
  320. RecDirFree                                                         RecDirFree
  321.  
  322.    NAME
  323.        RecDirFree -- Unlocks all locked paths (V10)
  324.        (dos V36)
  325.  
  326.    SYNOPSIS
  327.        void RecDirFree(RecDirInfo)
  328.  
  329.        void RecDirFree(struct RecDirInfo *);
  330.  
  331.    FUNCTION
  332.        This function is called internally when error occurs in
  333.        RecDirNext(), so you don't have to call it then!
  334.        You can only call it when you no longer want to use RecDirNext(),
  335.        before it finishes the scanning process.
  336.        You DO NOT have to call RecDirFree() when you get any error,
  337.        even DN_ERR_END (scanning process complete)!
  338.  
  339.    INPUTS
  340.        RecDirInfo - pointer to struct RecDirInfo which has been
  341.                     called with RecDirInit()
  342.  
  343.    RESULT
  344.        none
  345.  
  346.    SEE ALSO
  347.        RecDirInit(), RecDirNext(), RecDirNextTagList()
  348.  
  349. RecDirInit                                                         RecDirInit
  350.  
  351.    NAME
  352.        RecDirInit -- Initializes recursive files scanning process (V10)
  353.        (dos V36)
  354.  
  355.    SYNOPSIS
  356.        error = RecDirInit(RecDirInfo)
  357.  
  358.        UBYTE = RecDirInit(struct RecDirInfo *)
  359.  
  360.    FUNCTION
  361.        This function is required to start scanning files through entire
  362.        or partial directory tree. It locks a directory path provided in
  363.        RecDirInfo structure, then files can be examined by calling
  364.        RecDirNext() function. Please see RecDirNext() for more
  365.        explanation on how this is useful.
  366.        You should initialize RecDirInfo by yourself, and you MUST set
  367.        rdi_Path, rdi_Num, and rdi_Pattern.
  368.  
  369.    INPUTS
  370.        RecDirInfo - pointer to RecDirInfo structure, which should be
  371.        allocated and initialized before RecDirInit() is called.
  372.        You must set its rdi_Path field to starting directory path
  373.        you want to scan.
  374.        
  375.        Set rdi_Num for maximum number of directories you wish to scan
  376.        into. If you set rdi_Num to 1 it will only scan one level (that
  377.        rdi_Path points to). If you set rdi_Num to -1 it will scan
  378.        unlimited number of subdirectories deep.
  379.  
  380.        If rdi_Pattern field is non-NULL and points to a string then
  381.        calling RecDirNext will only return files that match the
  382.        pattern string. NOTE that rdi_Pattern should point to a string
  383.        which has been parsed with ParsePattern().
  384.  
  385.    RESULT
  386.        error - 0 if no error, otherwise returns one of the following
  387.        errors (also see libraries/supra.h):
  388.            RDI_ERR_FILE - Path provided in rdi_Path points to a file
  389.                           not directory.
  390.            RDI_ERR_NONEXIST - Path provided in rdi_Path does not exist.
  391.            RDI_ERR_MEM - not enough memory to execute RecDirInit().
  392.  
  393.    EXAMPLE
  394.        Please see an example in RecDirNext() function.
  395.  
  396.    NOTES
  397.        IMPORTANT: You MUST open dos.library before calling RecDirInit()!
  398.        rdi_Path is a path relative to a current path your program uses.
  399.        That means you can set rdi_Path to "" to scan from current
  400.        directory, or "/" to scan parent directory.
  401.  
  402.    BUGS
  403.        None found yet.
  404.  
  405.    SEE ALSO
  406.        RecDirFree(), RecDirNext(), libraries/supra.h
  407.  
  408. RecDirNext                                                         RecDirNext
  409.  
  410.    NAME
  411.        RecDirNext -- Gets information about the next file (V10)
  412.        (dos V36)
  413.  
  414.    SYNOPSIS
  415.        error = RecDirNext(RecDirInfo, RecDirFIB);
  416.  
  417.        UBYTE = RecDirNext(struct RecDirInfo *, struct RecDirFIB *);
  418.  
  419.    FUNCTION
  420.        Retrieves information about the next file in a scanning process.
  421.        Calling this function  will not provide a list of sorted files
  422.        niether by ASCII order nor by directory levels. That means
  423.        it will scan files as they have been stored on a disk drive.
  424.  
  425.        The main advantage of using this function from using ExNext()
  426.        is that you don't have to program a recursive scanning routine
  427.        by yourself. You need only to provide lowest directory path,
  428.        how deep into subdirectories you want to scan, and which
  429.        information about files you need to be provided with.
  430.        RecDirNext() will only return files but no directories.
  431.        You are also able to select a matching pattern so that only
  432.        files which match it will be returned.
  433.  
  434.        Please see RecDirInit() for more info.
  435.  
  436.    INPUTS
  437.        RecDirInfo - pointer to RecDirInfo structure. You MUST call
  438.        RecDirInit(), providing it with this structure, before calling
  439.        any RecDirNext() function.
  440.  
  441.        RecDirFIB - pointer to RecDirFIB structure which should be
  442.        previousely allocated. You only set those fields in the
  443.        structure that you want to have information about. Any field
  444.        should point to a variable into which information will be stored.
  445.        Check "struct RecDirFIB" to see what each field mean.
  446.        All field in RecDirFIB structure that are set to NULL will be
  447.        ignored.
  448.  
  449.    RESULT
  450.        error - zero if no error. Otherwise one of the following:
  451.            DN_ERR_END - scanning is completed. You should not call
  452.                         any RecDirNext() again.
  453.            DN_ERR_EXAMINE - Failure while examining a file.
  454.            DN_ERR_MEM - not enough memory available to complete
  455.                         the operation.
  456.            IF any error will be resulted, RecDirFree will be called
  457.            internally.
  458.  
  459.  
  460.    EXAMPLE
  461.        This example will scan through the entire HD0: disk device, and
  462.        will print for each file: its dir path, its name, its size.
  463.  
  464.  
  465.    #include <stdio.h>
  466.    #include <stdlib.h>
  467.    #include <clib/exec_protos.h>
  468.    #include <clib/dos_protos.h>
  469.    #include <libraries/supra.h>
  470.  
  471.    struct RecDirFIB rdf;
  472.    struct RecDirInfo rdi;
  473.    char name[30];
  474.    char path[100];
  475.    LONG size;
  476.    LONG err;
  477.  
  478.    struct DosBase *DosBase;
  479.  
  480.    void main()
  481.    {
  482.         if (DosBase = (struct DosBase *)OpenLibrary("dos.library",0)) {
  483.  
  484.            rdi.rdi_Path = "RAM:";  /* from path "RAM:" */
  485.            rdi.rdi_Num = -1;       /* Unlimited subdirs deep */
  486.            rdi.rdi_Pattern = NULL; /* Don't match files for pattern */
  487.  
  488.            if (RecDirInit(&rdi) == 0) {
  489.                rdf.Path = path;  /* We want to get files' path, name and size
  490.  */
  491.                rdf.Name = name;
  492.                rdf.Size = &size;
  493.                while ((err = RecDirNext(&rdi, &rdf)) == 0) {
  494.                    printf("%s (%s) %ld\n", path, name, size);
  495.                }
  496.  
  497.                /* Now check if DN_ERR_END or some other unexpected error */
  498.                switch (err) {
  499.                    case DN_ERR_END:
  500.                        printf("Scanning completed\n");
  501.                        break;
  502.                    case DN_ERR_EXAMINE:
  503.                        printf("Error: trouble examining a file\n");
  504.                        break;
  505.                    case DN_ERR_MEM:
  506.                        printf("Error: not enough memory\n");
  507.                }
  508.            }
  509.  
  510.            CloseLibrary((struct Library *)DosBase);
  511.        } else printf("Cannot open dos.library\n");
  512.    }
  513.  
  514.  
  515.    NOTES
  516.        If you want to end scanning earlier you have to call RecDirFree()!
  517.  
  518.    BUGS
  519.        none found
  520.  
  521.    SEE ALSO
  522.        RecDirInit(), RecDirTags(), RecDirFree(), libraries/supra.h
  523.  
  524. RecDirTags                                                         RecDirTags
  525.  
  526.    NAME
  527.        RecDirNextTagList -- Gets information about next file (V10)
  528.        (dos V36)
  529.  
  530.    SYNOPSIS
  531.        error = RecDirNextTagList(RecDirInfo, RecDirFIB, TagItems)
  532.  
  533.        UBYTE = RecDirNextTagList(struct RecDirInfo *, struct RecDirFIB *,
  534.                    struct TagItem *);
  535.  
  536.  
  537.        error = RecDirNextTags(RecDirInfo, RecDirFIB, tag1, ...)
  538.  
  539.        UBYTE = RecDirNextTags(struct RecDirInfo *, struct RecDirFIB *,
  540.                    ULONG tag1, ...);*
  541.  
  542.  
  543.    FUNCTION
  544.        This function does the same as RecDirNext() but it provides
  545.        a TagList extension. Any additional tags will override initial
  546.        settings in RecDirFIB structure.
  547.  
  548.    INPUTS
  549.        RecDirInfo - pointer to RecDirInfo structure which has been
  550.                     called with RecDirInit()
  551.        RecDirFIB  - pointer to initialized and set RecDirFIB structure,
  552.                     or NULL.
  553.                     You can get files' information either by setting
  554.                     variables to this structure before calling
  555.                     RecDirNextTagList(), or by providing TagItems you
  556.                     want. 
  557.                     NOTE: If you provide any TagItem then RecDirFIB will
  558.                     be changed (if it's non-NULL)!
  559.  
  560.        Tags - The following tags are available:
  561.  
  562.            RD_NAME - File name will be provided. ti_Data should carry
  563.                      a pointer to a string buffer (char *)
  564.            RD_PATH - Directory path where scanned file is.
  565.            RD_FULL - Full directory path + file name
  566.            RD_SIZE - File lenght in bytes. ti_Data must have a pointer to
  567.                      a LONG number (LONG *).
  568.            RD_FLAGS - File's protection flags. ti_Data must have a pointer
  569.                      to LONG.
  570.            RD_COMMENT - File's comment note. ti_Data carries a pointer to
  571.                      a string buffer.
  572.            RD_DATE - File's DateStamp structure. Function will copy the
  573.                      entire DateStamp structure into struct DateStamp
  574.                      provided in ti_Data field that points to it.
  575.            RD_BLOCKS - File size in blocks. ti_Data should have a pointer
  576.                        to LONG
  577.            RD_UID - Owner's UID (not supported with all file systems).
  578.                     ti_Data should have a pointer to UWORD variable.
  579.            RD_GID - Owner's GID. ti_Data has a pointer to UWORD variable.
  580.            RD_FIB - FileInfoBlock. Function will copy examined file's
  581.                     FileInfoBlock to a provided struct FileInfoBlock
  582.                     via ti_Data (ti_Data has a pointer to an allocated
  583.                     FileInfoBlock structure).
  584.  
  585.    RESULT
  586.        Same as for RecDirNext()
  587.  
  588.    EXAMPLE
  589.  
  590.        See an example for RecDirNext(). You can replace its line
  591.  
  592.        RecDirNext(&rdi, &rdf);
  593.           *with*
  594.        RecDirNextTags(&rdi, NULL, RD_PATH, path,
  595.                                   RD_NAME, name,
  596.                                   RD_SIZE, &size,
  597.                                   TAG_DONE);
  598.    NOTES
  599.        If RecDirFIB is not NULL, and you provide some tags as well then
  600.        RecDirFIB will be changed. This may change in the future so
  601.        that provided RecDirFIB will not change.
  602.  
  603.    BUGS
  604.        none found
  605.  
  606.    SEE ALSO
  607.        RecDirNext(), RecDirInit(), libraries/supra.h
  608.  
  609. RelPens                                                               RelPens
  610.  
  611.    NAME
  612.        RelPens -- Release a list of pens obtained by ObtPens (V10)
  613.        (gfx V39)
  614.    SYNOPSIS
  615.        RelPens(cm, PalTable, PensTable)
  616.  
  617.        void (struct ColorMap *, ULONG *, ULONG *);
  618.  
  619.    FUNCTION
  620.        This function repeats calls to ReleasePen() in order to
  621.        release all pens obtained by ObtPens().
  622.  
  623.    INPUTS
  624.        cm = colormap
  625.        PalTable - the same PalTable called with ObtPens()
  626.        PensTable - the same PensTable called with ObtPens()
  627.  
  628.    NOTES
  629.        Please DO NOT modify PalTable and PensTable between calling
  630.        ObtPens() and RelPens(). This function uses the first long
  631.        word from PalTable (describing number of entries and starting
  632.        position), and all entries from PensTable (except those entries
  633.        that are lower than a starting position).
  634.        You MUST open graphics library (V39 or higher) before calling
  635.        this function!
  636.  
  637.    SEE ALSO
  638.        ObtPens(), ReleasePen()
  639.  
  640.